package com.qining618.common.core.weixin.api;

import com.qining618.common.core.weixin.bean.sns.Jscode2sessionResult;
import com.qining618.common.utils.http.LocalHttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;

/**
 * @author flt
 * @date 2019-09-25
 */
public class SnsAPI extends BaseAPI {

    /**
     *  code 换取 session_key（微信小程序）
     * @param appid appid
     * @param secret secret
     * @param jsCode js_code
     * @return result
     */
    public static Jscode2sessionResult jscode2session(String appid, String secret, String jsCode){
        HttpUriRequest httpUriRequest = RequestBuilder.get()
                .setUri(BASE_URI + "/sns/jscode2session")
                .addParameter("appid",appid)
                .addParameter("secret",secret)
                .addParameter("js_code",jsCode)
                .addParameter("grant_type","authorization_code")
                .build();
        return LocalHttpClient.executeJsonResult(httpUriRequest,Jscode2sessionResult.class);
    }
}
